package com.matt.controller.pad;

import com.matt.commons.dto.sso.AreaDTO;
import com.matt.commons.dto.sso.StaffDTO;
import com.matt.commons.exception.BusinessException;
import com.matt.commons.model.StatusResponse;
import com.matt.domain.Children;
import com.matt.domain.Classes;
import com.matt.foundation.constant.PermissionConstant;
import com.matt.foundation.model.ErrorCode;
import com.matt.foundation.model.MemVerificationCache;
import com.matt.foundation.utils.annotation.RequiredPermissions;
import com.matt.foundation.vo.nursery.NurseryScheduleDetailVo;
import com.matt.service.ClassesService;
import com.matt.service.NurseryScheduleService;
import com.matt.service.remoteCall.SsoCallService;
import io.swagger.annotations.*;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

import static com.matt.foundation.constant.RequestConstant.TICKET;

;

/**
 * *******************************
 * 托班排课
 * Created by lch.
 * form com.matt
 * on 2018/11/26
 * *******************************
 */
@RestController
@RequestMapping(value = "/pad/nursery_schedule")
public class PadNurseryScheduleController {

    @Autowired
    private NurseryScheduleService nurseryScheduleService;

    @Autowired
    private SsoCallService ssoCallService;

    @Autowired
    private MemVerificationCache cache;

    @Autowired
    private ClassesService classesService;


    //托班排课列表
    @ApiOperation(value = "托班排课列表",httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "formData", name = "areaId", value = "园区Id", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "formData", name = "beginDate", value = "开始日期：yyyy-MM-dd", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "formData", name = "endDate", value = "结束日期：yyyy-MM-dd", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "formData", name = "filter", value = "0：所有类型课表， 1：园区课表， 2：家庭端课表", required = true, dataType = "integer"),
    })
    @ApiResponses({
		@ApiResponse(code = 000000, message = "成功"),
		@ApiResponse(code = 000001, message = "ticket已过期")
	}) 
    @RequestMapping(value = "/list")
    public StatusResponse scheduleList(String areaId, String beginDate, String endDate, @RequestParam(defaultValue = "1")  Integer filter) {
        return StatusResponse.success(nurseryScheduleService.scheduleList(areaId, beginDate, endDate, filter));
    }

    //托班排课详情
    @ApiOperation(value = "托班排课详情",httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "ticket", value = "票据", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "formData", name = "classesId", value = "班级id", required = false, dataType = "string"),
            @ApiImplicitParam(paramType = "formData", name = "courseDateStr", value = "课程日期：yyyy-MM-dd", required = false, dataType = "string"),
            @ApiImplicitParam(paramType = "formData", name = "nurseryScheduleId", value = "托班排课id", required = false, dataType = "string"),
    })
    @ApiResponses({
		@ApiResponse(code = 000000, message = "成功"),
		@ApiResponse(code = 000001, message = "ticket已过期")
	}) 
    @RequestMapping(value = "/detail")
    public StatusResponse scheduleDetail(String classesId, String courseDateStr, String nurseryScheduleId) {
        return StatusResponse.success(nurseryScheduleService.scheduleDetail(classesId, courseDateStr, nurseryScheduleId));
    }

    //老师托班排课列表
    @ApiOperation(value = "老师托班排课列表",httpMethod = "POST")
    @ApiImplicitParams({
		@ApiImplicitParam(paramType = "header", name = "ticket", value = "ticket", required = true, dataType = "string"),
    })
    @ApiResponses({
		@ApiResponse(code = 000000, message = "成功"),
		@ApiResponse(code = 000001, message = "ticket已过期")
	}) 
    @RequestMapping(value = "/classes_list")
    public StatusResponse scheduleTeacherList(@RequestHeader(TICKET) String ticket) {
        StaffDTO staff = cache.getStaff(ticket);

        if (ssoCallService.checkStaffPermission(ticket, new String[]{PermissionConstant.TEACH_CLASSES_FULL})){
            return StatusResponse.success(nurseryScheduleService.scheduleLeaderClassesList(staff.getAreaId()));
        }

        return StatusResponse.success(nurseryScheduleService.scheduleTeacherClassesList(staff.getId(), staff.getAreaId()));
    }

    //老师托班排课详情
    @ApiOperation(value = "老师托班排课详情",httpMethod = "POST")
    @ApiImplicitParams({
    	@ApiImplicitParam(paramType = "header", name = "ticket", value = "票据", required = true, dataType = "string"),
    	@ApiImplicitParam(paramType = "formData", name = "classesId", value = "班级id", required = false, dataType = "string"),
		@ApiImplicitParam(paramType = "formData", name = "courseDateStr", value = "课程日期：yyyy-MM-dd", required = false, dataType = "string"),
    })
    @ApiResponses({
		@ApiResponse(code = 000000, message = "成功"),
		@ApiResponse(code = 000001, message = "ticket已过期"),
	}) 
    @RequestMapping(value = "/teacher_detail")
    public StatusResponse scheduleTeacherDetail(String classesId, String courseDateStr) {
        if (StringUtils.isBlank(classesId))
            throw new BusinessException(ErrorCode.CLASSES_IS_BLANK,"老师没有对应的的班级");
        return StatusResponse.success(nurseryScheduleService.scheduleTeacherDetail(classesId, courseDateStr));
    }

    @ApiOperation(value = "上门服务的宝宝列表，如果当前老师是园长则查询全园的上门服务宝宝，否则只查询当前老师相关的",httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "ticket", value = "票据", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "formData", name = "classesId", value = "班级ID", required = false, dataType = "string"),
            @ApiImplicitParam(paramType = "formData", name = "childrenName", value = "宝宝名字，模糊查找", required = false, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code = 000000, message = "成功"),
            @ApiResponse(code = 000001, message = "ticket已过期"),
    })
    @RequestMapping(value = "/door2DoorChildren")
    public StatusResponse door2DoorChildren(@RequestHeader(TICKET)String ticket, String childrenName) {

        StaffDTO staffDTO  = ssoCallService.getStaffDTO(ticket);

        List<Children>  list = null;

        if (ssoCallService.checkStaffPermission(ticket, new String[]{PermissionConstant.TEACH_CLASSES_FULL})){
            //园长
            list = nurseryScheduleService.door2DoorChildren(staffDTO.getAreaId(), null, childrenName);
        }else{
            list = nurseryScheduleService.door2DoorChildren(staffDTO.getAreaId(), staffDTO.getId(), childrenName);
        }

        return StatusResponse.success(list);
    }

    @ApiOperation(value = "课表详情, teacher_detail的增强接口",httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "ticket", value = "票据", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "formData", name = "classesId", value = "班级id", required = false, dataType = "string"),
            @ApiImplicitParam(paramType = "formData", name = "childrenId", value = "宝宝id", required = false, dataType = "string"),
            @ApiImplicitParam(paramType = "formData", name = "teacherId", value = "老师id", required = false, dataType = "string"),
            @ApiImplicitParam(paramType = "formData", name = "courseDateStr", value = "课程日期：yyyy-MM-dd", required = false, dataType = "string"),
    })
    @ApiResponses({
            @ApiResponse(code = 000000, message = "成功"),
            @ApiResponse(code = 000001, message = "ticket已过期"),
    })
    @RequestMapping(value = "/scheduler_detail")
    public StatusResponse schedulerDetail(@RequestHeader String ticket,
                                          String classesId, String childrenId, String teacherId, String courseDateStr) {

        if (ssoCallService.checkStaffPermission(ticket, new String[]{PermissionConstant.TEACH_CLASSES_FULL})){

        }else if (StringUtils.isBlank(teacherId)){
            StaffDTO staff = cache.getStaff(ticket);
            teacherId = staff.getId();
        }

        if (StringUtils.isBlank(classesId)  && StringUtils.isBlank(childrenId)) {
            throw new BusinessException(ErrorCode.CLASSES_IS_BLANK, "请指定班级信息");
        }

        NurseryScheduleDetailVo detail = null;

        if (StringUtils.isNotBlank(childrenId) && StringUtils.isBlank(teacherId)){
            detail = nurseryScheduleService.scheduleFullChildrenDetail(childrenId, courseDateStr);
        }else{
            detail = nurseryScheduleService.scheduleTeacherDetail(classesId, childrenId, teacherId, courseDateStr);
        }


        return StatusResponse.success(detail);
    }

    //托班排课新增
    @ApiOperation(value = "托班排课新增",httpMethod = "POST" ,notes="json category 0：非主题课 1：主题课 数据格式 [{'activityContent':'活动内容1','category':'1','begin':'08:00','end':'09:00'},{'activityContent':'活动内容2','category':'1','begin':'08:00','end':'09:00'}]")
    @ApiImplicitParams({
    	@ApiImplicitParam(paramType = "header", name = "ticket", value = "票据", required = true, dataType = "string"),
    	@ApiImplicitParam(paramType = "query", name = "classesId", value = "班级id", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "query", name = "childrenId", value = "宝宝id", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "query", name = "teacherId", value = "老师Id", required = true, dataType = "string"),
		@ApiImplicitParam(paramType = "query", name = "lessonDate", value = "课程时间 yyyy-MM-dd ", required = true, dataType = "string"),
		@ApiImplicitParam(paramType = "query", name = "scheduleJson", value = "排课详情记录 json 数据格式", required = true, dataType = "string"),
    })
    @ApiResponses({
		@ApiResponse(code = 000000, message = "成功"),
		@ApiResponse(code = 000001, message = "ticket已过期")
	}) 
    @RequestMapping(value = "/add")
    public StatusResponse scheduleAdd(@RequestHeader String ticket,
                                      String classesId, String childrenId, String teacherId,
                                      String lessonDate, String scheduleJson) {
        if (scheduleJson == null || "[]".equals(scheduleJson) || StringUtils.isBlank(scheduleJson)){
            return StatusResponse.error(ErrorCode.NURSERY_SCHEDULE_IS_BLANK, "排课详情不能为空！");
        }
        StaffDTO staff = cache.getStaff(ticket);

        return StatusResponse.success(nurseryScheduleService.scheduleAdd(classesId, childrenId, teacherId,staff.getAreaId(), lessonDate, scheduleJson));
    }

    //托班排课修改
    @ApiOperation(value = "托班排课修改",httpMethod = "POST",notes="json category 0：非主题课 1：主题课 数据格式 [{'activityContent':'活动内容1','category':'1','begin':'08:00','end':'09:00'},{'activityContent':'活动内容2','category':'1','begin':'08:00','end':'09:00'}]")
    @ApiImplicitParams({
    	@ApiImplicitParam(paramType = "header", name = "ticket", value = "票据", required = true, dataType = "string"),
    	@ApiImplicitParam(paramType = "query", name = "nurseryScheduleId", value = "排课id", required = true, dataType = "string"),
		@ApiImplicitParam(paramType = "query", name = "scheduleJson", value = "排课详情记录 json 数据格式", required = true, dataType = "string")
    })
    @ApiResponses({
		@ApiResponse(code = 000000, message = "成功"),
		@ApiResponse(code = 000001, message = "ticket已过期")
	}) 
    @RequestMapping(value = "/update")
    public StatusResponse scheduleUpdate(@RequestHeader(TICKET)String ticket ,String nurseryScheduleId, String scheduleJson) {
        StaffDTO staff = cache.getStaff(ticket);
        return StatusResponse.success(nurseryScheduleService.scheduleUpdate(nurseryScheduleId,staff.getAreaId(), scheduleJson));
    }

    //删除托班排课记录
    @ApiOperation(value = "删除托班排课记录",httpMethod = "POST")
    @ApiImplicitParams({
    	@ApiImplicitParam(paramType = "header", name = "ticket", value = "票据", required = true, dataType = "string"),
    	@ApiImplicitParam(paramType = "formData", name = "id", value = "记录id", required = true, dataType = "string"),
    })
    @ApiResponses({
		@ApiResponse(code = 000000, message = "成功"),
		@ApiResponse(code = 000001, message = "ticket已过期")
	}) 
    @RequestMapping(value = "/delete_schedule_record")
    public StatusResponse deleteScheduleRecord(String id) {
        return StatusResponse.success(nurseryScheduleService.deleteScheduleRecord(id));
    }

    //托班排课保存为模版
    @ApiOperation(value = "托班排课保存为模版",httpMethod = "POST",notes="json category 0：非主题课 1：主题课 数据格式 [{'activityContent':'活动内容1','category':'1','begin':'08:00','end':'09:00'},{'activityContent':'活动内容2','category':'1','begin':'08:00','end':'09:00'}]")
    @ApiImplicitParams({
    	@ApiImplicitParam(paramType = "header", name = "ticket", value = "ticket", required = true, dataType = "string"),
		@ApiImplicitParam(paramType = "query", name = "areaId", value = "园区Id ", required = true, dataType = "string"),
		@ApiImplicitParam(paramType = "formData", name = "name", value = "模版名称", required = true, dataType = "string"),
		@ApiImplicitParam(paramType = "formData", name = "lessonDate", value = "课程时间 yyyy-MM-dd ", required = true, dataType = "string"),
		@ApiImplicitParam(paramType = "formData", name = "scheduleJson", value = "排课详情记录 json 数据格式", required = true, dataType = "string"),
    })
    @ApiResponses({
		@ApiResponse(code = 000000, message = "成功"),
		@ApiResponse(code = 000001, message = "ticket已过期")
	}) 
    @RequestMapping(value = "/temp_save")
    public StatusResponse scheduleTempSave(@RequestHeader String ticket, String areaId, String name, String lessonDate, String scheduleJson) {
        if (scheduleJson == null || "[]".equals(scheduleJson) || StringUtils.isBlank(scheduleJson))
            return StatusResponse.error(ErrorCode.NURSERY_SCHEDULE_IS_BLANK, "排课详情不能为空！");
        StaffDTO baseInfo = cache.getStaff(ticket);
        String staffId = baseInfo.getId();
        return StatusResponse.success(nurseryScheduleService.scheduleTempAdd(areaId, staffId, name, lessonDate, scheduleJson));
    }

    //加载模版
    @ApiOperation(value = "加载模版",httpMethod = "POST")
    @ApiImplicitParams({
    	@ApiImplicitParam(paramType = "header", name = "ticket", value = "ticket", required = true, dataType = "string"),
		@ApiImplicitParam(paramType = "query", name = "areaId", value = "园区Id ", required = true, dataType = "string"),
    })
    @ApiResponses({
		@ApiResponse(code = 000000, message = "成功"),
		@ApiResponse(code = 000001, message = "ticket已过期")
	}) 
    @RequestMapping(value = "/load_temp")
    public StatusResponse loadTemp(@RequestHeader String ticket) {
        StaffDTO staff = cache.getStaff(ticket);
        return StatusResponse.success(nurseryScheduleService.loadTemp(staff.getAreaId(), staff.getId()));
    }

    //删除模版
    @ApiOperation(value = "删除模版",httpMethod = "POST")
    @ApiImplicitParams({
    	@ApiImplicitParam(paramType = "header", name = "ticket", value = "ticket", required = true, dataType = "string"),
		@ApiImplicitParam(paramType = "formData", name = "id", value = "模版id", required = true, dataType = "string"),
    })
    @ApiResponses({
		@ApiResponse(code = 000000, message = "成功"),
		@ApiResponse(code = 000001, message = "ticket已过期")
	}) 
    @RequestMapping(value = "/delete_temp")

    @RequiredPermissions(PermissionConstant.TEACH_NURSERY_SCHEDULE_DELETE)
    public StatusResponse deleteTemp(@RequestHeader String ticket, String id) {
        return StatusResponse.success(nurseryScheduleService.deleteTemp(id));
    }

    //托班提交审核
    @ApiOperation(value = "托班提交审核",httpMethod = "POST")
    @ApiImplicitParams({
    	@ApiImplicitParam(paramType = "header", name = "ticket", value = "ticket", required = true, dataType = "string"),
		@ApiImplicitParam(paramType = "query", name = "areaId", value = "模版id", required = true, dataType = "string"),
		@ApiImplicitParam(paramType = "formData", name = "checkId", value = "id", required = false, dataType = "string"),
		@ApiImplicitParam(paramType = "formData", name = "isSure", value = "审核状态 '0：首次提交  1：确认提交'", required = true, dataType = "integer"),
		@ApiImplicitParam(paramType = "formData", name = "classesId", value = "班级id", required = true, dataType = "string"),
		@ApiImplicitParam(paramType = "formData", name = "beginDate", value = "起止时间 格式：'yyyy-MM-dd'", required = true, dataType = "string"),
		@ApiImplicitParam(paramType = "formData", name = "endDate", value = "最终时间 格式：'yyyy-MM-dd'", required = true, dataType = "string"),
    })
    @ApiResponses({
		@ApiResponse(code = 000000, message = "成功"),
		@ApiResponse(code = 000001, message = "ticket已过期"),
		@ApiResponse(code = 1000009, message = "确认只排xx天课程吗？")
	}) 
    @RequestMapping(value = "/submit_check")
    public StatusResponse submitCheck(@RequestHeader String ticket, String areaId, String checkId, Integer isSure, String classesId, String beginDate, String endDate) {
        if (isSure != null && isSure == 0 && StringUtils.isBlank(checkId)) {
            int count = nurseryScheduleService.findCountByClassesIdAndTime(classesId, beginDate, endDate);
            if (count < 1)
                return StatusResponse.error(ErrorCode.UNDER_ONE_DAY, "这周还未排课");
            if (1 <= count && count < 5)
                return StatusResponse.error(ErrorCode.UNDER_FIVE_DAY, "这周确定只排" + count + "天课吗？");
        }
        StaffDTO baseInfo = cache.getStaff(ticket);
        String staffId = baseInfo.getId();
        String realName = baseInfo.getRealName();
        return StatusResponse.success(nurseryScheduleService.submitCheck(areaId, staffId, realName, checkId, classesId, beginDate, endDate));
    }


    //老师——托班排课详情 (单天查询)
    @ApiOperation(value = "老师——托班排课详情 (单天查询)",httpMethod = "POST")
    @ApiImplicitParams({
    	@ApiImplicitParam(paramType = "header", name = "ticket", value = "票据", required = true, dataType = "string"),
		@ApiImplicitParam(paramType = "formData", name = "classesId", value = "班级id", required = true, dataType = "string"),
		@ApiImplicitParam(paramType = "formData", name = "courseDate", value = "课程时间 格式'yyyy-MM-dd'", required = true, dataType = "string"),
    })
    @ApiResponses({
		@ApiResponse(code = 000000, message = "成功"),
		@ApiResponse(code = 000001, message = "ticket已过期")
	}) 
    @RequestMapping(value = "/check_detail")
    public StatusResponse checkDetail(String classesId, String courseDate) {
        return StatusResponse.success(nurseryScheduleService.checkDetail(classesId, courseDate));
    }

    //老师--托班排课详情（一周）
    @ApiOperation(value = "老师--托班排课详情（一周）",httpMethod = "POST")
    @ApiImplicitParams({
    	@ApiImplicitParam(paramType = "header", name = "ticket", value = "票据", required = true, dataType = "string"),
  		@ApiImplicitParam(paramType = "formData", name = "checkId", value = "审核id", required = true, dataType = "string"),
     })
    @ApiResponses({
		@ApiResponse(code = 000000, message = "成功"),
		@ApiResponse(code = 000001, message = "ticket已过期")
	}) 
    @RequestMapping(value = "/check_detail_week")
    public StatusResponse checkDetailWeek(@RequestHeader String ticket, String checkId) {
        AreaDTO area = ssoCallService.getAreaDTO(ticket);
        return StatusResponse.success(nurseryScheduleService.checkDetailWeek(area, checkId));
    }

    //获取托班审核
    @ApiOperation(value = "获取托班审核",httpMethod = "POST")
    @ApiImplicitParams({
    	@ApiImplicitParam(paramType = "header", name = "ticket", value = "票据", required = true, dataType = "string"),
		@ApiImplicitParam(paramType = "formData", name = "classesId", value = "班级id", required = true, dataType = "string"),
		@ApiImplicitParam(paramType = "formData", name = "beginDate", value = "开始时间 格式'yyyy-MM-dd'", required = true, dataType = "string"),
		@ApiImplicitParam(paramType = "formData", name = "endDate", value = "结束时间 格式'yyyy-MM-dd'", required = true, dataType = "string"),
    })
    @ApiResponses({
		@ApiResponse(code = 000000, message = "成功"),
		@ApiResponse(code = 000001, message = "ticket已过期")
	}) 
    @RequestMapping(value = "/get_schedule_check")
    public StatusResponse getNurseryScheduleCheck(String classesId, String beginDate, String endDate) {
        return StatusResponse.success(nurseryScheduleService.getNurseryScheduleCheck(classesId, beginDate, endDate));
    }

    //打印天一日生活流程
    @ApiOperation(value = "打印天一日生活流程",httpMethod = "POST")
    @ApiImplicitParams({
    	@ApiImplicitParam(paramType = "header", name = "ticket", value = "票据", required = true, dataType = "string"),
		@ApiImplicitParam(paramType = "formData", name = "nurseryScheduleId", value = "排课id", required = true, dataType = "string"),
    })
    @ApiResponses({
		@ApiResponse(code = 000000, message = "成功"),
		@ApiResponse(code = 000001, message = "ticket已过期")
	}) 
    @RequestMapping(value = "/print_day_data")
    public StatusResponse printDaySchedule(@RequestHeader String ticket, String nurseryScheduleId) {
        StaffDTO staff = ssoCallService.getStaffDTO(ticket);
        AreaDTO area = ssoCallService.getAreaDTO(ticket);

        return StatusResponse.success(nurseryScheduleService.getPrintDaySchedule(staff, area, nurseryScheduleId));
    }

    //打印周一日生活流程
    @ApiOperation(value = "打印周一日生活流程",httpMethod = "POST")
    @ApiImplicitParams({
    	@ApiImplicitParam(paramType = "header", name = "ticket", value = "票据", required = true, dataType = "string"),
		@ApiImplicitParam(paramType = "formData", name = "checkId", value = "审核id", required = true, dataType = "string"),
		@ApiImplicitParam(paramType = "formData", name = "type", value = "类型  1：时间相同  2：时间不相同", required = true, dataType = "integer"),
    })
    @ApiResponses({
		@ApiResponse(code = 000000, message = "成功"),
		@ApiResponse(code = 000001, message = "ticket已过期")
	}) 
    @RequestMapping(value = "/print_week_data")
    public StatusResponse printWeekSchedule(@RequestHeader String ticket, String checkId, Integer type) {
         AreaDTO area = ssoCallService.getAreaDTO(ticket);
        return StatusResponse.success(nurseryScheduleService.getPrintWeekSchedule(area, checkId, type));
    }

    //自动排课接口
    @ApiOperation(value = "自动排课接口",httpMethod = "POST")
    @ApiImplicitParams({
		@ApiImplicitParam(paramType = "formData", name = "classesId", value = "班级Id", required = true, dataType = "string"),
		@ApiImplicitParam(paramType = "formData", name = "lessonDate", value = "排课时间", required = true, dataType = "date"),
    })
    @ApiResponses({
		@ApiResponse(code = 000000, message = "成功"),
		@ApiResponse(code = 000021, message = "当天已排课")
	}) 
    @RequestMapping(value = "/addNurseryInstrationByDay")
    public StatusResponse addNurseryInstrationByDay(@RequestHeader String ticket, String classesId, Date lessonDate) {
        AreaDTO area = ssoCallService.getAreaDTO(ticket);
        if (lessonDate == null || StringUtils.isBlank(classesId)){
        	 return StatusResponse.error(ErrorCode.PARAM_CAN_NOT_BLANK, "需要指定排课班级和排课日期！");
        }

        Classes classes = classesService.getClassesById(area.getId(), classesId);
        if (classes == null){
            throw new BusinessException(ErrorCode.CLASSES_NOT_EXIST, "指定班级不存在");
        }

        return StatusResponse.success(nurseryScheduleService.nurseryScheduleRecordAdd(area.getId(), classesId, lessonDate));
    }
    
    //获取一日指导资源
    @ApiOperation(value = "(新)获取一日指导资源",httpMethod = "POST")
    @ApiImplicitParams({
    	@ApiImplicitParam(paramType = "header", name = "ticket", value = "票据", required = true, dataType = "string"),
		@ApiImplicitParam(paramType = "formData", name = "classesId", value = "班级Id", required = true, dataType = "string"),
		@ApiImplicitParam(paramType = "formData", name = "lessonDate", value = "排课时间", required = true, dataType = "string"),
		@ApiImplicitParam(paramType = "formData", name = "type", value = "类型  1：运动  2：游戏 3：喝奶 4：辅食 5：自定义", required = true, dataType = "integer"),

    })
    @ApiResponses({
		@ApiResponse(code = 000000, message = "成功"),
		@ApiResponse(code = 000001, message = "ticket已过期"),
	}) 
    @RequestMapping(value = "/getInstrationResourceByClassesId")
    public StatusResponse getInstrationResourceByClassesId(@RequestHeader String ticket, String classesId,String lessonDate,Integer type) {
        if (classesId == null){
        	 return StatusResponse.error(ErrorCode.CLASSES_IS_BLANK, "班级不能为空！");
        }
        return StatusResponse.success(nurseryScheduleService.getInstructionRescourceByClassesId(classesId, lessonDate,type));
    }


    /**
     * 托班一日生活
     * @param classesId 班级ID
     * @param courseDateStr 日期 此日期只能是一周的第一天(星期一)
     * @return
     */
    @ApiOperation(value = "导出一周的托班一日生活Excel",httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "ticket", value = "票据", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "formData", name = "classesId", value = "班级Id", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "formData", name = "courseDateStr", value = "日期 此日期只能是一周的第一天(星期一)", required = true, dataType = "string"),

    })
    @RequestMapping(value = "/export_excel")
    public StatusResponse exportExcel(@RequestHeader String ticket, String classesId, String courseDateStr) {
        StaffDTO staff = ssoCallService.getStaffDTO(ticket);

        if (StringUtils.isBlank(courseDateStr)){
            return StatusResponse.error(ErrorCode.PARAM_CAN_NOT_BLANK, "需要指定排课班级和排课日期！");
        }

        String result = nurseryScheduleService.exportExcel(staff.getAreaId(), staff.getId(), classesId, courseDateStr);

        return StatusResponse.success(result);
    }

}
